//
//  FinanceInfoView.m
//  SUZHOUBANK
//
//  Created by saberLily on 16/4/11.
//  Copyright © 2016年 RuiFeng-WGCC. All rights reserved.
//

#import "FinanceInfoView.h"
#import "TopScrollView.h"
#import "DefineHeader.h"
#import "PubScrollView.h"
#import "CenterView.h"
#import "BottomTableView.h"
@interface FinanceInfoView()
@property (nonatomic,strong) TopScrollView *topScrollView; /**< 上滚动图 */

@property (nonatomic,strong) CenterView *centerFirst; /**< 第一个视图 */

@property (nonatomic,strong) CenterView *centerSecondView; /**< 第二个的视图 */

@property (nonatomic,strong) PubScrollView *centerScrollView; /**< 中 */
@property (nonatomic,strong) PubScrollView *centerSecondScrollView; /**< s */

@property (nonatomic,strong)  BottomTableView *bottomView; /**< 底部tableview */
@property (nonatomic,strong) CenterView *bottomTableview; /**< 底部Tableview */

@property (nonatomic,strong) UIScrollView *bacScrollView; /**< 背景滚动图 */
@end
@implementation FinanceInfoView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self initializeDataSource];
        [self initializeUserInterface];
    }
    return self;
}

#pragma mark - initializeDataSource 初始化数据源
-(void)initializeDataSource{
    [self getApirequest];
  [self getNewsAPIRequest];
}

#pragma mark - initializeUserInterface 初始化用户界面
-(void)initializeUserInterface{
    [self addSubview:self.bacScrollView];
    
    [self.bacScrollView addSubview:self.topScrollView];
    
    
}

#pragma mark *** PrivateMethods ***
-(void)getApirequest{
    
    NSArray *arr = @[@"熊猫纪念币套装",@"艺术品投资—朝鲜油画—出嫁",@"艺术品投资—朝鲜油画—天池",@"艺术品收藏—核雕",@"艺术品收藏—刺绣",@"福禄双全",@"喜福至阖家欢银月饼",@"苏州四大园林"];
    
    [BaseAPIManager requestURL:@"protocol_recommend_product!update.action" parameters:nil completion:^(bool success, NSInteger status, NSDictionary *data, NSError *error) {
        for (id obj in data[@"datalist"]) {
//             NSLog(@"%@",obj[@"NAME"]);
//             NSLog(@"%@",obj[@"PICURL"]);
            if ( [arr containsObject:obj[@"NAME"]]  ) {
                [self.centerScrollView.imageUrlArr addObject:obj[@"PICURL"]];
                [self.centerScrollView.imageName addObject:obj[@"NAME"]];
            }
        }
        [self.centerScrollView initializeUserInterface];
        
        
        [self.bacScrollView addSubview:self.centerSecondView];
      
       
        
 
    }];
}
-(void)getNewsAPIRequest{
    NSArray *arr = @[@"熊猫纪念币套装",@"艺术品投资—朝鲜油画—出嫁",@"艺术品投资—朝鲜油画—天池",@"艺术品收藏—核雕",@"艺术品收藏—刺绣",@"福禄双全",@"喜福至阖家欢银月饼",@"苏州四大园林"];
    
    [BaseAPIManager requestURL:@"protocol_recommend_product!update.action" parameters:nil completion:^(bool success, NSInteger status, NSDictionary *data, NSError *error) {
        for (id obj in data[@"datalist"]) {
            //             NSLog(@"%@",obj[@"NAME"]);
            //             NSLog(@"%@",obj[@"PICURL"]);
            if ( [arr containsObject:obj[@"NAME"]]  ) {
                [self.centerSecondScrollView.imageUrlArr addObject:obj[@"PICURL"]];
                [self.centerSecondScrollView.imageName addObject:obj[@"NAME"]];
            }
        }
        
        [self.centerSecondScrollView initializeUserInterface];
        
        [self.bacScrollView addSubview:self.centerFirst];
        
        
        
    }];
}
#pragma mark *** getters ***

-(UIScrollView *)bacScrollView{
    if (!_bacScrollView) {
        _bacScrollView = [[UIScrollView alloc] initWithFrame:self.bounds];
        
        _bacScrollView.contentSize = CGSizeMake(CGRectGetWidth(self.bounds), CGRectGetMaxY(self.bottomTableview.frame)+100);
        _bacScrollView.bounces = false;
        _bacScrollView.contentOffset = CGPointMake(0, 0);
        _bacScrollView.scrollEnabled = true;
        _bacScrollView.showsVerticalScrollIndicator = NO;
        _bacScrollView.showsHorizontalScrollIndicator = NO;
        _bacScrollView.backgroundColor = [UIColor clearColor];
        
    }
    return _bacScrollView;
}

-(TopScrollView *)topScrollView{
    if (!_topScrollView) {
        _topScrollView = [[TopScrollView alloc]initWithFrame:CGRectMake(50, 40, 1100, 380)];
    }
    return _topScrollView;
}

-(CenterView *)centerFirst{
    if (!_centerFirst) {
        _centerFirst = [[CenterView alloc] initWithFrame:CGRectMake(50, 430, 1100, 250)];
        _centerFirst.titleImage.image = [UIImage imageNamed:@"金融资讯_新闻分类"];
        _centerFirst.titleLabel.text = @"重要新闻";
        _centerFirst.rightView.image = [UIImage imageNamed:@"右滑"];
        
        [_centerFirst addSubview:self.centerSecondScrollView];
    }
    return _centerFirst;
}

-(CenterView *)centerSecondView{
    if (!_centerSecondView) {
        _centerSecondView = [[CenterView alloc] initWithFrame:CGRectMake(50, CGRectGetMaxY(self.centerFirst.frame)+80, 1100, 250)];
        _centerSecondView.titleImage.image = [UIImage imageNamed:@"金融资讯_新推分类"];
        _centerSecondView.titleLabel.text = @"热推产品";
        _centerSecondView.rightView.image = [UIImage imageNamed:@"右滑"];
        
        [_centerSecondView addSubview:self.centerScrollView];
        
    }
    return _centerSecondView;
}

-(PubScrollView *)centerScrollView{
    if (!_centerScrollView) {
        
        _centerScrollView = [[PubScrollView alloc] initWithFrame:CGRectMake(0, 80, 1100, 250) ScrollStyle:ScrollStyleTitleAndImage];
        
    }
    return _centerScrollView;
}

-(PubScrollView *)centerSecondScrollView{
    if (!_centerSecondScrollView) {
        _centerSecondScrollView = [[PubScrollView alloc] initWithFrame:CGRectMake(0, 80, 1100, 250) ScrollStyle:ScrollStyleImageAndTitle];
    }
    return _centerSecondScrollView;
}


-(BottomTableView *)bottomView {
    if (!_bottomView) {
        _bottomView = [[BottomTableView alloc] initWithFrame:CGRectMake(0, 80, 1100, 250)];
    }
    return _bottomView;
}
-(CenterView *)bottomTableview{
    if (!_bottomTableview) {
        _bottomTableview = [[CenterView alloc] initWithFrame:CGRectMake(50, CGRectGetMaxY(self.centerSecondView.frame)+80, 1100, 300)];
        _bottomTableview.titleImage.image = [UIImage imageNamed:@"金融资讯_公告分类"];
        _bottomTableview.titleLabel.text = @"最新公告";
        
        _bottomTableview.rightView.image = [UIImage imageNamed:@"下滑"];
        
        [_bottomTableview addSubview:self.bottomView];
    }
    return _bottomTableview;
}
@end
